// 棋局状态
let ChessStatus = {}
// 棋手信息
ChessStatus.userinfo = {
    //白棋 ：步数 棋子位置
    u_AI: { countSteps: 0, postionList: [] },
    u_YOU: { countSteps: 0, postionList: [] }
    //黑棋 ：步数 棋子位置
}

ChessStatus.start = false //未开局
ChessStatus.win_Zi_arr = []//当前落子能赢的全部坐标
ChessStatus.AI_win_Zi_arr = [] //AI当前落子能赢的全部坐标
ChessStatus.Allchess = new Array(225)// 0 所有点上的落子归属 默认是 0无 1黑 2白
ChessStatus.User_history = [] // 顺序记录所有落子信息  走子历史记录
ChessStatus.AllchessQ = new Array(225)//所有点落子权重
ChessStatus.Max_qn = 0 //最大权重的位置编号 0-225
ChessStatus.now_zi = {}//当前落子所在 元素
ChessStatus.play_actionAudio = true //播放落子声音
ChessStatus.Ai_with_You = true //开启AI和您对局


ChessStatus.colorPad = []
// 默认执棋人 黑棋先手 
ChessStatus.Who_First = "YOU" //AI后手 执白棋
ChessStatus.Hei_Qizi_Color = "linear-gradient(-50deg, rgb(0, 0, 0) 40%, rgb(97, 97, 97) 100%)"
ChessStatus.Bai_Qizi_Color = "linear-gradient(-50deg, rgb(129, 129, 129) 30%,rgb(255,255,255,1) 100%)"
ChessStatus.Ai_Qizi_Color = ChessStatus.Bai_Qizi_Color
ChessStatus.You_Qizi_Color = ChessStatus.Hei_Qizi_Color
ChessStatus.uid_YOU = "B"
ChessStatus.uid_AI = "W"
ChessStatus.whoTrun = "YOU" //
ChessStatus.uid_YOUQ = 1
ChessStatus.uid_AIQ = 2
//头像
ChessStatus.pic_YOU = "url('./img/u-pic.jpg')"
ChessStatus.pic_AI = "url('./img/ai-pic.png')"
// ID
ChessStatus.id_YOU = "Artificial Intelligence"
ChessStatus.id_AI = "静水致远"
// 悔棋最大次数
ChessStatus.roll_back_n = 5
// 预加载音频文件
let sound_luozi = new Audio();
sound_luozi.src = './dis/5390.mp3';
sound_luozi.preload = "auto"
sound_luozi.load();
// 预加载音频文件
let sound_win = new Audio();
sound_win.src = './dis/win.mp3';
sound_win.preload = "auto"
sound_win.load();
// 预加载音频文件
let sound_lose = new Audio();
sound_lose.src = './dis/lose.mp3';
sound_lose.preload = "auto"
sound_lose.load();

// 右下侧信息
inforpad = getElementByXpath("//*[@id='right_user']/div[2]")
inforpad.innerHTML = "等待开局..."
// 禁止操作层，出现后，棋盘上YOU不能落子
mask = document.getElementById("mask_")
// "AI先手"切换按钮点击
turn_bt = document.getElementById('turn_button')
turn_bt.addEventListener('click', change_first)
/**
 *切换AI先后手，界面显示
 *下棋计时器数值
*/
let Timer_obj = {
    AI: { total: 0, step: 0, timer_tid: "", timer_sid: "" },
    YOU: { total: 0, step: 0, timer_tid: "", timer_sid: "" }
}
let timerInterval, Timer_obj_AI_total, Timer_obj_YOU_total, Timer_obj_AI_step, Timer_obj_YOU_step
Timer_obj_AI_total = getElementByXpath('//*[@id="left_user"]//*[@id="total_time"]')
Timer_obj_YOU_total = getElementByXpath('//*[@id="right_user"]//*[@id="total_time"]')
Timer_obj_AI_step = getElementByXpath('//*[@id="left_user"]//*[@id="step_time"]')
Timer_obj_YOU_step = getElementByXpath('//*[@id="right_user"]//*[@id="step_time"]')

Timer_obj_AI_total.innerHTML = "00:00"
Timer_obj_YOU_total.innerHTML = "00:00"
Timer_obj_AI_step.innerHTML = "00:00"
Timer_obj_YOU_step.innerHTML = "00:00"

AI_max_qn = 0
// Ai思考loading动画
let thinking_el = document.getElementById("thinking")
thinking_el.style.display = "none"
// 定时器，用于延时显示动画及按钮元素
let change_first_timer, timer_rollback, timer_thinking, timer_win_show
// 处理谁先手参数及动画
function change_first() {
    // 获取头像，用于交换位置
    left_p = getElementByXpath('//*[@id="left_user"]/div[1]/div[1]')
    right_p = getElementByXpath('//*[@id="right_user"]/div[1]/div[1]')
    left_id = getElementByXpath('//*[@id="left_user"]/div[1]/div[2]')
    right_id = getElementByXpath('//*[@id="right_user"]/div[1]/div[2]')
    // 清除谁先手定时器
    clearTimeout(change_first_timer)

    if (!ChessStatus.start) {
        if (ChessStatus.Ai_with_You) {
            if (ChessStatus.Who_First == "YOU") {
                // 切换为AI先手  AI是黑棋
                ChessStatus.Who_First = "AI" //AI先手 执黑棋
                turn_bt.innerHTML = "AI后手"
                left_p.style.animation = "wobble 200ms  1"
                right_p.style.animation = "wobble 200ms  1"
                left_p.style.backgroundImage = ChessStatus.pic_YOU
                right_p.style.backgroundImage = ChessStatus.pic_AI
                Timer_obj_YOU_total = getElementByXpath('//*[@id="left_user"]//*[@id="total_time"]')
                Timer_obj_AI_total = getElementByXpath('//*[@id="right_user"]//*[@id="total_time"]')
                Timer_obj_YOU_step = getElementByXpath('//*[@id="left_user"]//*[@id="step_time"]')
                Timer_obj_AI_step = getElementByXpath('//*[@id="right_user"]//*[@id="step_time"]')
                left_id.innerHTML = ChessStatus.id_AI
                right_id.innerHTML = ChessStatus.id_YOU
                inforpad.innerHTML = "等待开局...<br>您为后手"

            } else {
                // 切换为AI后手 AI 是白棋
                ChessStatus.Who_First = "YOU" //AI后手 执白棋
                turn_bt.innerHTML = "AI先手"
                left_p.style.animation = "wobble 200ms  1"
                right_p.style.animation = "wobble 200ms  1"
                left_p.style.backgroundImage = ChessStatus.pic_AI
                right_p.style.backgroundImage = ChessStatus.pic_YOU
                Timer_obj_AI_total = getElementByXpath('//*[@id="left_user"]//*[@id="total_time"]')
                Timer_obj_YOU_total = getElementByXpath('//*[@id="right_user"]//*[@id="total_time"]')
                Timer_obj_AI_step = getElementByXpath('//*[@id="left_user"]//*[@id="step_time"]')
                Timer_obj_YOU_step = getElementByXpath('//*[@id="right_user"]//*[@id="step_time"]')

                left_id.innerHTML = ChessStatus.id_YOU
                right_id.innerHTML = ChessStatus.id_AI
                inforpad.innerHTML = "等待开局...<br>您为先手"

            }
            // 延时是为了显示先手时头像图片交换时的动画
            change_first_timer = setTimeout(function () {
                left_p.style.removeProperty("animation")
                right_p.style.removeProperty("animation")
            }, 300)

        }
    }
}
/**
 *分配棋子颜色 和基础权重
 *
 */
function intCh() {

    if (ChessStatus.Who_First === "AI") {
        // ai执黑棋先手  位置标识 为2
        ChessStatus.Ai_Qizi_Color = ChessStatus.Hei_Qizi_Color
        ChessStatus.You_Qizi_Color = ChessStatus.Bai_Qizi_Color

        ChessStatus.whoTrun = "AI"
        ChessStatus.uid_YOU = "W"
        ChessStatus.uid_AI = "B"
    } else {
        // ai执白棋棋后手  位置标识 为1
        ChessStatus.Ai_Qizi_Color = ChessStatus.Bai_Qizi_Color
        ChessStatus.You_Qizi_Color = ChessStatus.Hei_Qizi_Color

        ChessStatus.whoTrun = "YOU"
        ChessStatus.uid_YOU = "B"
        ChessStatus.uid_AI = "W"
    }
    // console.log("先手=>", ChessStatus.Who_First)
}
/**
 *画棋盘落子位置 15*15 格
 *
 * @return {string}  HTML元素字符串
 */
function get_Luozi_Element(count) {
    count = 15
    let qpHTML = ''
    for (let index = 0; index < count; index++) {
        for (let j = 0; j < count; j++) {
            qpHTML = qpHTML + "<div class='wqqz' id=" + index + "," + j + " status='0' number=" + ((index) * 15 + j + 1) + "></div>"
        }
    }
    return qpHTML
}
start_bt = document.getElementById('start_button')
// 点击开始按钮
start_bt.onclick = function () {
    // 清除赢棋局的画面显示定时器
    clearTimeout(timer_win_show)
    // 显示和隐藏一些元素
    this.style.display = "none"
    turn_bt.style.display = "none"
    mask.style.display = "none"
    thinking_el.style.display = "none"
    // 设定悔棋最多次数
    ChessStatus.roll_back_n = 100
    // 初始最大权重为0
    AI_max_qn = 0
    document.getElementById('roll_back').innerHTML = "悔 棋(" + ChessStatus.roll_back_n + ")"
    let qpHTML
    if (ChessStatus.start === false) {
        // 分配棋子颜色 和基础权重
        intCh()
        // 初始化走棋信息记录
        ChessStatus.userinfo = {
            u_AI: { countSteps: 0, postionList: [] },
            u_YOU: { countSteps: 0, postionList: [] }
        }
        ChessStatus.win_Zi_arr = [] //当前落子能赢的全部坐标
        ChessStatus.AI_win_Zi_arr = [] //AI当前落子能赢的全部坐标 
        ChessStatus.Allchess = new Array(225)// 0 所有点上的落子归属 0无 1黑 2白
        ChessStatus.User_history = [] // 顺序记录所有落子信息 走子历史记录
        ChessStatus.AllchessQ = new Array(225)//所有点落子权重
        ChessStatus.Max_qn = 0//落子的最大权重计为0
        // 所有位置落子权重置0
        for (i = 1; i <= 225; i++) {
            ChessStatus.AllchessQ[i] = 0;
        }
        for (i = 1; i <= 225; i++) {
            ChessStatus.Allchess[i] = 0;
        }
        //画棋盘的落子位置（即十字交叉处） 
        qpHTML = get_Luozi_Element(15)
        // 把落子点添加到棋盘上（十字交叉落子位置）
        document.querySelector(".qizi_box").innerHTML = qpHTML

        // 添加落子点后，监听落子动作
        let chlist = document.getElementsByClassName('wqqz')
        //对局开始
        ChessStatus.start = true
        //开始监听下棋动作。
        for (let index = 0; index < chlist.length; index++) {
            chUnit = chlist[index];
            chUnit.status = false
            // 监听落子动作
            chUnit.addEventListener('click', Luozi)
            // 监听鼠标在棋盘移动 进行位置提醒
            chUnit.addEventListener('mouseenter', Alert_box)
        }
        // 如果AI先手，则AI第一次落子
        if (ChessStatus.Who_First == "AI") {
            mask.style.display = "block"
            // 4~10 Math.floor(Math.random() * (m - n)) + n
            x = Math.floor(Math.random() * (10 - 4 + 1) + 4)
            y = Math.floor(Math.random() * (10 - 4 + 1) + 4)
            element = document.getElementById(x + "," + y)
            Ai_luozi(element)
            ChessStatus.whoTrun = "YOU"
            mask.style.display = "none"
            inforpad.innerHTML = "开局了，您为后手。"
        }
        else {
            inforpad.innerHTML = "开局了，您为先手。"
        }
    } else {
        alert("已经开局")
    }
}

/**
 *悔棋
 *
 *
 */

function roll_back() {
    if (!ChessStatus.start || ChessStatus.User_history.length < 2 || ChessStatus.roll_back_n < 1 || ChessStatus.whoTrun == "AI") {
        // 悔棋条件不满足
        document.getElementById('roll_back').setAttribute("disabled", "disabled")
        console.log(ChessStatus.roll_back_n)
        return
    }
    for (let i = 0; i < 2; i++) {
        // 擦除棋子画面
        el = document.getElementById(ChessStatus.User_history[ChessStatus.User_history.length - 1].xy)
        el.style.removeProperty("animation")
        el.style.animation = "bounceOut 200ms 1"
        el.style.animationFillMode = "forwards"
        el.innerHTML = ""
        // status
        el.status = 0
        // 每个落子点，添加落子动作监听
        el.addEventListener("click", Luozi)
        // 添加落子位置提示
        el.addEventListener('mouseenter', Alert_box)
        el.removeAttribute('style')
        // 更新历史记录 ChessStatus.User_history
        ChessStatus.User_history.pop()
        // 所有棋子落点 ChessStatus.Allchess
        ChessStatus.Allchess[el.getAttribute("number")] = 0
        // 如果i==0 即为处理YOU的落子数据
        if (i === 0) {
            // 步数   ChessStatus.userinfo.u_AI.countSteps
            ChessStatus.userinfo.u_AI.countSteps--
            // YOU走棋记录 ChessStatus.userinfo.u_AI.postionList
            ChessStatus.userinfo.u_AI.postionList.pop()
        } else {
            // 步数   ChessStatus.userinfo.u_YOU.countSteps
            ChessStatus.userinfo.u_YOU.countSteps--
            // YOU走棋记录 ChessStatus.userinfo.u_YOU.postionList
            ChessStatus.userinfo.u_YOU.postionList.pop()
        }
        // 清除所有后加的style样式 定时是为了能显示棋子消失的动画
        timer_rollback = setTimeout(function () {
            el.removeAttribute("style");
        }, 250)
    }
    ChessStatus.roll_back_n--
    this.innerHTML = "悔 棋(" + ChessStatus.roll_back_n + ")"
}
// 添加悔棋和认输按钮点击监听
document.getElementById("get_draw").onclick = get_draw
document.getElementById("get_lose").onclick = get_draw

function get_draw() {
    if (!ChessStatus.start) {
        return
    }
    // 弹出确认提示
    let el = document.getElementById("alert")
    el.style.display = "block"
    let show = document.getElementById("ask_for_peace")
    show.style.display = "block"
    let msg = document.querySelector("#ask_for_peace .msg_infor");
    let yes = document.getElementById("bt_y")
    let type
    if (this.id === "get_draw") {
        msg.innerHTML = "确定要 “和棋” 吗？"
        type = "drwa"
    } else {
        msg.innerHTML = "确定要 “认输” 吗？"
        type = "lose"
    }

    yes.onclick = function () {
        el.style.display = "none"
        // 结束棋局
        ChessStatus.start = false
        mask.style.display = "block"
        thinking_el.style.display = "none"
        start_bt.style.display = "block"
        turn_bt.style.display = "block"
        if (type === "draw") {

        } else {

        }
    }
    let no = document.getElementById("bt_n")
    // 如果是确定按钮 结束本局，记录棋局记录
    // 如果是取消按钮 继续对局
    no.onclick = function () {
        el.style.display = "none"
    }

}
// 
/**
 *AI落子画面显示
 *
 */
function Ai_luozi(element) {
    drawPiece(element) //显示落子画面
    updatMap(element) //更新棋手信息
    element.removeEventListener('mouseenter', Alert_box)
    element.removeEventListener('click', Luozi)
    // console.log("AI 落子=>", element.getAttribute("number"))
    stopTimer(Timer_obj.AI.timer_tid)
    let tarr = Timer_obj_AI_total.innerHTML.split(":")
    // let sarr = Timer_obj_AI_total.innerHTML.split(":")
    Timer_obj.AI.total = Number(tarr[0]) * 60 + Number(tarr[1])
    stopTimer(Timer_obj.AI.timer_sid)
}

//
/**
 *执行落子动作,并进行输赢判断
 *
*/
function Luozi() {
    clearTimeout(timer_rollback)
    clearTimeout(timer_thinking)//清理定时器
    //落子成功，并进行选手信息更新
    if (ChessStatus.start) {
        // 落子计时停止
        stopTimer(Timer_obj.YOU.timer_tid)
        let tarr = Timer_obj_YOU_total.innerHTML.split(":")
        Timer_obj.YOU.total = Number(tarr[0]) * 60 + Number(tarr[1])
        stopTimer(Timer_obj.YOU.timer_sid)

        drawPiece(this) //显示落子画面s
        updatMap(this) //更新棋手信息

        //更新一些界面状态
        this.status = '1'
        // 把元素绑定到一个变量上，以用来传递参数
        let el = this
        // 移除落子监听
        this.removeEventListener('click', Luozi)
        document.getElementById('roll_back').setAttribute("disabled", "disabled")
        //检查是否有五子相连(判赢)
        let ifwinF = ifwin(this)
        if (ifwinF !== false && ifwinF.length == 5) {
            // 显示赢棋画面
            for (let i = 0; i < ifwinF.length; i++) {
                draw_alert_Win_Luozi(ifwinF[i])
            }
            // 结束棋局
            stopTimer(Timer_obj.YOU.timer_tid)
            let tarr = Timer_obj_YOU_total.innerHTML.split(":")
            Timer_obj.YOU.total = Number(tarr[0]) * 60 + Number(tarr[1])
            stopTimer(Timer_obj.YOU.timer_sid)

            stopTimer(Timer_obj.AI.timer_tid)
            let tarr2 = Timer_obj_AI_total.innerHTML.split(":")
            Timer_obj.AI.total = Number(tarr2[0]) * 60 + Number(tarr2[1])
            stopTimer(Timer_obj.AI.timer_sid)
            sound_win.play()
            inforpad.innerHTML = "您赢了！"
            ChessStatus.start = false
            mask.style.display = "block"
            return
        } else {
            // 落子计时
            startTimer(Timer_obj_AI_total, Timer_obj.AI.total)
            Timer_obj.AI.timer_tid = timerInterval
            startTimer(Timer_obj_AI_step, 0)
            Timer_obj.AI.timer_sid = timerInterval
            mask.style.display = "block"
            thinking_el.style.display = "block"

            if (ChessStatus.You_Qizi_Color === ChessStatus.Bai_Qizi_Color) {
                inforpad.innerHTML = "<div id='zi_info' style='background-image:" + ChessStatus.Ai_Qizi_Color + "'></div>等待：黑 方落子"
            } else {
                inforpad.innerHTML = "<div id='zi_info' style='background-image:" + ChessStatus.Ai_Qizi_Color + "'></div>等待：白  方落子"
            }
            // 随机延时，模拟AI思考

            delaytime = Math.floor(Math.random() * (2000 - 500 + 1) + 500)
            timer_thinking = setTimeout(function () {
                // 轮到AI落子
                ChessStatus.whoTrun = 'AI'

                // 先计算落子权重
                AiQ()
                // AI_q(el)
                // 获取最高权重
                max_q = 0
                max_arr = []
                max_number = 0
                ChessStatus.Max_qn = 0
                // 这一步初步筛选出，有权重的放到一个数据
                for (i = 1; i <= 225; i++) {
                    k = ChessStatus.AllchessQ[i];
                    if (k >= max_q) {
                        max_q = k
                        if (k != 0) {
                            // console.log(k)
                            max_arr.push([k, i])
                        }
                        // i是number 编号 K 是权重 
                        max_number = k
                    }
                }
                // 第二步，是把相同的最大值的放一个数组里
                max_q2 = 0
                max_arr2 = []
                for (i = 0; i < max_arr.length; i++) {
                    k = max_arr[i][0]
                    if (k == max_number) {
                        max_arr2.push(max_arr[i])
                    }
                }
                // console.log("max_arr", max_arr)
                // console.log("max_arr2", max_arr2)
                // 第三步在所有的最大值中随机取一个出来做为落子点
                find_number = Math.floor(Math.random() * max_arr2.length)
                ChessStatus.Max_qn = max_arr2[find_number][1]
                // AI执行落子
                element = getElementByXpath('//div[@number="' + ChessStatus.Max_qn + '"]')
                AI_max_qn = max_number
                Ai_luozi(element)

                // 落子计时
                startTimer(Timer_obj_YOU_total, Timer_obj.YOU.total)
                Timer_obj.YOU.timer_tid = timerInterval
                startTimer(Timer_obj_YOU_step, 0)
                Timer_obj.YOU.timer_sid = timerInterval

                document.getElementById('roll_back').removeAttribute("disabled")
                if (ChessStatus.roll_back_n > 0) {
                    // 悔棋                              
                    document.getElementById('roll_back').addEventListener("click", roll_back)
                }
                // 开始悔棋计时

                //  判断输赢
                let ifwinT = ifwin(element)
                if (ifwinT !== false && ifwinT.length == 5) {
                    // 显示赢棋画面
                    let arr_d = []  //存储数字坐标 用来画赢画面特效。
                    for (let i = 0; i < ifwinT.length; i++) {
                        t_obj = document.getElementById(ifwinT[i]).getAttribute("number")
                        arr_d.push([Number(t_obj), ifwinT[i]])
                        // console.log("Number(t_obj):",Number(t_obj))
                        draw_alert_Win_Luozi(ifwinT[i])
                    }
                    // console.log(Math.min(...arr_d ))
                    // console.log(ifwinT[2]); // 0	
                    console.log(Math.max(...arr_d))
                    // 结束棋局
                    stopTimer(Timer_obj.YOU.timer_tid)
                    let tarr = Timer_obj_YOU_total.innerHTML.split(":")
                    Timer_obj.YOU.total = Number(tarr[0]) * 60 + Number(tarr[1])
                    stopTimer(Timer_obj.YOU.timer_sid)

                    stopTimer(Timer_obj.AI.timer_tid)
                    let tarr2 = Timer_obj_AI_total.innerHTML.split(":")
                    Timer_obj.AI.total = Number(tarr2[0]) * 60 + Number(tarr2[1])
                    stopTimer(Timer_obj.AI.timer_sid)
                    sound_lose.play()
                    inforpad.innerHTML = "您输了！"
                    ChessStatus.start = false
                    return
                }
                // 该YOU落子
                ChessStatus.whoTrun = "YOU"
                mask.style.display = "none" //去除遮罩层
                // 更新右侧提示面板提示信息
                if (ChessStatus.You_Qizi_Color === ChessStatus.Bai_Qizi_Color) {
                    inforpad.innerHTML = "<div id='zi_info' style='background-image:" + ChessStatus.You_Qizi_Color + "'></div>等待：白 方落子"
                } else {
                    inforpad.innerHTML = "<div id='zi_info' style='background-image:" + ChessStatus.You_Qizi_Color + "'></div>等待：黑 方落子"
                }
                // console.log("所有落子坐标=>",ChessStatus.Allchess)
                // console.log("所有能赢坐标=>",ChessStatus.win_Zi_arr)  
            }, delaytime)
        }

    }
}

/**
 *落子后并进行画面更新，播放声音
 *
 * @param {*} obj
 * @return {*} 
 */
function drawPiece(obj) {
    if (obj.status == '0') {
        if (ChessStatus.whoTrun == "AI") {
            obj.style.backgroundImage = ChessStatus.Ai_Qizi_Color
        } else {
            obj.style.backgroundImage = ChessStatus.You_Qizi_Color
            AI_max_qn = ''
        }
        // 显示落子动画
        e = document.getElementsByClassName('shizi')[0]
        if (e) { e.remove() }//去掉当前落子红色图形标识提示
        obj.style.boxShadow = "3px 3px 3px #666"
        obj.style.animation = "heartBeat 200ms  1"
        obj.style.lineHeight = "38px"
        obj.style.textAlign = "center"
        obj.style.color = "yellow"
        // 显示已活落子的权重  AI_max_qn 为计算出来的当前最大权重
        // obj.innerHTML = String(AI_max_qn) + "<div class='gaoliang'></div><div class='shizi'></div>"
        obj.innerHTML =  "<div class='gaoliang'></div><div class='shizi'></div>"
    } else {
        return false
    }
    // 播放落子声音
    if (ChessStatus.play_actionAudio) { sound_luozi.play() }
    return true
}

/**
 *棋子强调显示画面 
 *
 * @param {String} id 当前元素id "x,y"
 */
function draw_alert_Win_Luozi(id) {
    obj = document.getElementById(id)
    obj.style.border = "dashed 2px red"
    obj.style.animation = "glow 300ms ease-in-out 5"
    // let c_elm = document.createElement("div")
    // c_elm.setAttribute("class", "line_alter")
    // obj.appendChild(c_elm)
    thinking_el.style.display = "none"
    ChessStatus.roll_back_n = 0
    // 恢复悔棋按钮文字内容
    document.getElementById('roll_back').innerHTML = "悔 棋"
    timer_win_show = setTimeout(() => {
        start_bt.style.display = "block"
        turn_bt.style.display = "block"
    }, 2000);
}

/**
 *显示提示落子位置画面
 *
 */
function Alert_box() {
    if (ChessStatus.start == false || this.status == "1") {
        this.removeEventListener('mouseenter', Alert_box)
        return
    }
    text = this.innerHTML
    style = this.style
    this.innerHTML = this.innerHTML + "<div class='alert_box' style='float:left'></div>"
    this.addEventListener('mouseleave', Ereasalert_box)
}
//
/**
 *擦除显示提示落子位置画面 *
*/
function Ereasalert_box() {
    if (this.status == '0') {
        this.innerHTML = this.innerText
    }
    this.removeEventListener('mouseleave', Ereasalert_box)
}

/**
 *更新棋手走棋记录
 *
 * @param {Element} obj 
 * @return {Boolean} 
 */
function updatMap(obj) {
    if (obj.status == '0') {
        let history
        if (ChessStatus.whoTrun == "AI") {
            // 更新棋手信息
            history = { uid: ChessStatus.uid_AI, xy: obj.id, x: obj.id.split(',')[0], y: obj.id.split(',')[1] }
            // 添加AI走棋记录
            ChessStatus.userinfo.u_AI.postionList.push(history)
            // 统计步数
            ChessStatus.userinfo.u_AI.countSteps++
            // 记录棋盘当前坐标
            ChessStatus.Allchess[obj.getAttribute("number")] = ChessStatus.uid_AIQ
        } else {
            history = { uid: ChessStatus.uid_YOU, xy: obj.id, x: obj.id.split(',')[0], y: obj.id.split(',')[1] }
            // 添加YOU走棋记录
            ChessStatus.userinfo.u_YOU.postionList.push(history)
            // 统计步数
            ChessStatus.userinfo.u_YOU.countSteps++
            // 记录棋盘当前坐标为黑棋
            ChessStatus.Allchess[obj.getAttribute("number")] = ChessStatus.uid_YOUQ
        }
        // 添加全局走子历史记录
        ChessStatus.User_history.push(history)

        // console.log("落子记录=>", ChessStatus.User_history)
        // console.log("每点落子=>", ChessStatus.Allchess)
        // console.log("落子数值=>", ChessStatus.Allchess[obj.getAttribute("number")])
        return true
    } else {
        return false
    }
}


/**
 * 判断输赢即一方已五子相连 
 *
 * @param {Element} obj   当前落子位置的元素
 * @return {boolean} 不相连则返回false，相连返回五子的坐标数组，元素格式 “x,y”
 * @return{Array}
 */
function ifwin(obj) {
    xy = obj.id.split(',')
    x = xy[0]
    y = xy[1]
    win_zi_arr = checkFive(x, y); //获取能赢所有可能性的坐标组信息
    // 当前选手目前所有落子
    user_zi_arr = ChessStatus.whoTrun == "YOU" ? ChessStatus.userinfo.u_YOU : ChessStatus.userinfo.u_AI
    //去杂项，把能赢的坐标组 整理后的 XY 坐标,把分散的合成到一个数组里去
    user_zi_xy = []
    for (let i = 0; i < user_zi_arr.postionList.length; i++) {
        user_zi_xy.push(user_zi_arr.postionList[i].xy)
    }
    // console.log('选手所有落子', user_zi_xy)
    // console.log('所有能赢的可能性', win_zi_arr)

    for (let i = 0; i < win_zi_arr.length; i++) {
        count = 0
        for (value of user_zi_xy) {
            if (win_zi_arr[i].indexOf(value) != -1) {
                count++
            } else {
                continue
            }
        }
        if (count >= 5) {
            return win_zi_arr[i]
        }
    }
    return false
}

/**
 *计算以当前落子位置为中心八个方向上， 
 五子相连的所有能赢的可能性。
 *
 * @param {int} x X坐标 
 * @param {int} y Y坐标 
 * @return {Array} 数组 每个数组元素是一组以包含当前落子在内的能赢五连子坐标
 */
function checkFive(x, y) {
    // 几个临时数组变量用来倒腾数组推入元素

    var winarr = [], temparr = [], temparr_list = []
    /**
     *私有函数，某个方向五连字的可能性的组合
     *
     * @param {*} temparr
     */
    function zhuhe_keneng(temparr) {
        for (let i = 0; i < 5 && i <= temparr.length - 5; i++) {
            for (let j = 0; j < 5; j++) {
                temparr_list.push(temparr[i + j])
            }
            if (temparr_list.length == 5) {
                winarr.push(temparr_list)
                temparr_list = []
            }
        }
    }
    // 左
    for (let i = 4; i >= 1; i--) {
        if (Number(y) - i >= 0) {
            temparr.push(x + "," + String(Number(y) - i))
        }
    }
    temparr.push(x + "," + y)
    // 右
    for (let i = 1; i < 5; i++) {
        if (Number(y) + i <= 16) {
            temparr.push(x + "," + String(Number(y) + i))
        }

    }
    zhuhe_keneng(temparr)


    // 上
    temparr = []
    for (let i = 4; i >= 1; i--) {
        if (Number(x) - i >= 0) {
            temparr.push(String(Number(x) - i + "," + y))
        }
    }
    temparr.push(x + "," + y)
    //下
    for (let i = 1; i < 5; i++) {
        if (Number(x) + i <= 16) {
            temparr.push(String(Number(x) + i + "," + y))
        }

    }
    zhuhe_keneng(temparr)

    // 左上
    temparr = []
    for (let i = 4; i >= 1; i--) {
        if (Number(y) - i >= 0 && Number(x) - i >= 0) {
            temparr.push(String(Number(x) - i) + "," + String(Number(y) - i))
        }

    }
    temparr.push(x + "," + y)
    // 右下
    for (let i = 1; i < 5; i++) {
        if (Number(y) + i <= 16 && Number(x) + i <= 16) {
            temparr.push(String(Number(x) + i) + "," + String(Number(y) + i))
        }

    }
    zhuhe_keneng(temparr)

    //  左下
    temparr = []
    for (let i = 4; i >= 1; i--) {
        if (Number(x) + i <= 16 && Number(y) - i >= 0) {
            temparr.push(String(Number(x) + i) + "," + String(Number(y) - i))
        }

    }
    temparr.push(x + "," + y)
    // // 右上
    for (let i = 1; i < 5; i++) {
        if (Number(x) - i >= 0 && Number(y) + i <= 16) {
            temparr.push(String(Number(x) - i) + "," + String(Number(y) + i))
        }

    }
    zhuhe_keneng(temparr)
    ChessStatus.win_Zi_arr = winarr
    return winarr;


}

// AI算法
function AiQ() {
    //人机对战AI选子，加权计算
    let jqn = new Array(225) //所有权重
    let pn = ChessStatus.Allchess //所有落子信息 0未落子 1黑方 2白方

    for (i = 1; i <= 225; i++) {
        jqn[i] = 0;
    }
    for (i = 1; i <= 15; i++) {    //遍历scan B & W 子
        let k
        let border_left = false; //
        let border_right = false; //
        for (j = 1; j <= 15; j++) {
            k = (i - 1) * 15 + j;    //pn(n) number
            // 非左右两边 不然影响
            border_left = false; //
            border_right = false; //
            if ((k - 1) % 15 == 0) {
                border_left = true;
            }
            if (k % 15 == 0) {
                border_right = true
            }

            temparr = []
            // //独子 左右上下 二对角 八方
            // /*
            // 0 0 0
            // 0 2 0
            // 0 0 0
            // */
            if (pn[k] == 2) {
                // 白棋 左右两条边和四个角需要特殊处理
                if (pn[k - 1] == 0) {
                    if ((k - 1) % 15 != 0) {
                        jqn[k - 1] = jqn[k - 1] + 20
                    }
                }
                if (pn[k + 1] == 0) {
                    if ((k + 1) % 15 != 1) {
                        jqn[k + 1] = jqn[k + 1] + 20
                    }
                }
                if (pn[k - 15] == 0) {
                    jqn[k - 15] = jqn[k - 15] + 20
                }
                if (pn[k + 15] == 0) {
                    jqn[k + 15] = jqn[k + 15] + 20
                }
                if (pn[k + 14] == 0 && k + 14) {
                    if ((k + 14) % 15 != 0) {
                        jqn[k + 14] = jqn[k + 14] + 20
                    }
                }
                if (pn[k + 16] == 0) {
                    if ((k + 16) % 15 != 1) {
                        jqn[k + 16] = jqn[k + 16] + 20
                    }
                }
                if (pn[k - 14] == 0) {
                    if ((k - 14) % 15 != 1) {
                        jqn[k - 14] = jqn[k - 14] + 20
                    }
                }
                if (pn[k - 16] == 0) {
                    // 靠左边
                    if ((k - 16) % 15 != 0) {
                        jqn[k - 16] = jqn[k - 16] + 20
                    }
                }
            }
            // 二连 0220
            if (pn[k] == 2 && pn[k + 1] == 2) {  //左右
                if ((k - 2) % 15 == 0) {
                    if (pn[k - 1] == 0) {
                        jqn[k - 1] = jqn[k - 1] + 320
                        jqn[k + 2] = jqn[k + 2] + 520
                    }
                } else if ((k + 2) % 15 == 0) {
                    jqn[k - 1] = jqn[k - 1] + 520
                    jqn[k + 2] = jqn[k + 2] + 320
                } else if (k > 1 && k < 13) {
                    jqn[k - 1] = jqn[k - 1] + 320
                    jqn[k + 2] = jqn[k + 2] + 320
                } else if (k > 210 && k < 223) {
                    jqn[k - 1] = jqn[k - 1] + 320
                    jqn[k + 2] = jqn[k + 2] + 320
                } else {
                    if (pn[k - 1] == 0) {
                        jqn[k - 1] = jqn[k - 1] + 520
                    }
                    if (pn[k + 2] == 0) {
                        jqn[k + 2] = jqn[k + 2] + 520
                    }
                }
            }

            if (pn[k] == 2 && pn[k + 15] == 2) {  //上下
                if (pn[k - 15] == 0) {
                    jqn[k - 15] = jqn[k - 15] + 520
                }
                if (pn[k + 30] == 0) {
                    jqn[k + 30] = jqn[k + 30] + 520
                }
            }

            if (pn[k] == 2 && pn[k + 14] == 2) {  //左对角
                if (pn[k - 14] == 0) {
                    jqn[k - 14] = jqn[k - 14] + 520
                }
                if (pn[k + 28] == 0) {
                    jqn[k + 28] = jqn[k + 28] + 520
                }
            }

            if (pn[k] == 2 && pn[k + 16] == 2) {  //右对角
                if (pn[k - 16] == 0) {
                    jqn[k - 16] = jqn[k - 16] + 520
                }
                if (pn[k + 32] == 0) {
                    jqn[k + 32] = jqn[k + 32] + 520
                }
            }


            //嵌三   02020    +1020 为活三冲四进攻点
            if (pn[k] == 2 && pn[k + 1] == 0 && pn[k + 2] == 2) {  //左右
                jqn[k + 1] = jqn[k + 1] + 520
                if (pn[k - 1] == 0) {
                    jqn[k - 1] = jqn[k - 1] + 1020
                }

                if (pn[k + 3] == 0) {
                    jqn[k + 3] = jqn[k + 3] + 1020
                }
            }

            if (pn[k] == 2 && pn[k + 15] == 0 && pn[k + 30] == 2) {  //上下
                jqn[k + 15] = jqn[k + 15] + 520
                if (pn[k - 15] == 0) {
                    jqn[k - 15] = jqn[k - 15] + 1020
                }
                if (pn[k + 45] == 0) {
                    jqn[k + 45] = jqn[k + 45] + 1020
                }
            }

            if (pn[k] == 2 && pn[k - 14] == 0 && pn[k - 28] == 2) {  //左对角
                jqn[k - 14] = jqn[k - 14] + 520
                if (pn[k + 14] == 0) {
                    jqn[k + 14] = jqn[k + 14] + 1020
                }
                if (pn[k - 42] == 0) {
                    jqn[k - 42] = jqn[k + 45] + 1020
                }
            }

            if (pn[k] == 2 && pn[k + 16] == 0 && pn[k + 32] == 2) {  //右对角
                jqn[k + 16] = jqn[k + 16] + 520
                if (pn[k - 16] == 0) {
                    jqn[k - 16] = jqn[k - 16] + 1020
                }
                if (pn[k + 48] == 0) {
                    jqn[k + 48] = jqn[k + 48] + 1020
                }
            }

            //三连，眠三抢冲四  12220  02221
            if (pn[k] == 2 && pn[k + 1] == 2 && pn[k + 2] == 2) {  //左右
                if (pn[k - 1] == 0) {
                    jqn[k - 1] = jqn[k - 1] + 2320
                }
                if (pn[k + 3] == 0) {
                    jqn[k + 3] = jqn[k + 3] + 2320
                }
            }

            if (pn[k] == 2 && pn[k + 15] == 2 && pn[k + 30] == 2) {  //上下
                if (pn[k - 15] == 0) {
                    jqn[k - 15] = jqn[k - 15] + 2320
                }
                if (pn[k + 45] == 0) {
                    jqn[k + 45] = jqn[k + 45] + 2320
                }
            }
            if (pn[k] == 2 && pn[k - 14] == 2 && pn[k - 28] == 2) {  //左对角
                if (pn[k + 14] == 0) {
                    jqn[k + 14] = jqn[k + 14] + 2320
                }
                if (pn[k - 42] == 0) {
                    jqn[k - 42] = jqn[k - 42] + 2320
                }
            }
            if (pn[k] == 2 && pn[k + 16] == 2 && pn[k + 32] == 2) {  //右对角
                if (pn[k - 16] == 0) {
                    jqn[k - 16] = jqn[k - 16] + 2320
                }
                if (pn[k + 48] == 0) {
                    jqn[k + 48] = jqn[k + 48] + 2320
                }
            }

            //三连，活三变活四，必杀  0022200    +2000
            if (pn[k - 2] == 0 && pn[k - 1] == 0 && pn[k] == 2 && pn[k + 1] == 2 && pn[k + 2] == 2 && pn[k + 3] == 0 && pn[k + 4] == 0) {  //左右
                jqn[k - 1] = jqn[k - 1] + 6500;
                jqn[k + 3] = jqn[k + 3] + 6500;
            }

            if (pn[k - 30] == 0 && pn[k - 15] == 0 && pn[k] == 2 && pn[k + 15] == 2 && pn[k + 30] == 2 && pn[k + 45] == 0 && pn[k + 60] == 0) {  //上下
                jqn[k - 15] = jqn[k - 15] + 6500;
                jqn[k + 45] = jqn[k + 45] + 6500;
            }

            if (pn[k - 28] == 0 && pn[k - 14] == 0 && pn[k] == 2 && pn[k + 14] == 2 && pn[k + 28] == 2 && pn[k + 42] == 0 && pn[k + 56] == 0) {//左对角
                jqn[k - 14] = jqn[k - 14] + 6500;
                jqn[k + 42] = jqn[k + 42] + 6500;
            }

            if (pn[k - 32] == 0 && pn[k - 16] == 0 && pn[k] == 2 && pn[k + 16] == 2 && pn[k + 32] == 2 && pn[k + 48] == 0 && pn[k + 64] == 0) {//右对角
                jqn[k - 16] = jqn[k - 16] + 6500;
                jqn[k + 48] = jqn[k + 48] + 6500;
            }

            //*********
            //白子算杀，做杀，找活三嵌四交点 +2500

            //嵌四类 做冲四 2022  2202   布杀点 +1800 ,j<12  防越界
            // 120220  122020 020221 022021
            if (j < 12) {
                if (pn[k] == 2 && pn[k + 1] == 0 && pn[k + 2] == 2 && pn[k + 3] == 2) {  //左右
                    if (pn[k - 1] == 0 || pn[k + 4] == 0) { jqn[k + 1] = jqn[k + 1] + 1800; }
                }
                if (pn[k] == 2 && pn[k + 1] == 2 && pn[k + 2] == 0 && pn[k + 3] == 2) {  //左右
                    if (pn[k - 1] == 0 || pn[k + 4] == 0) { jqn[k + 2] = jqn[k + 2] + 1800; }
                }
            } //j<12

            if (i < 12) {
                if (pn[k] == 2 && pn[k + 15] == 0 && pn[k + 30] == 2 && pn[k + 45] == 2) {  //上下
                    if (pn[k - 15] == 0 || pn[k + 60] == 0) { jqn[k + 15] = jqn[k + 15] + 1800; }
                }
                if (pn[k] == 2 && pn[k + 15] == 2 && pn[k + 30] == 0 && pn[k + 45] == 2) {  //上下
                    if (pn[k - 15] == 0 || pn[k + 60] == 0) { jqn[k + 30] = jqn[k + 30] + 1800; }
                }
            } //i<12

            if (j > 4 && i < 12) {
                if (pn[k] == 2 && pn[k + 14] == 0 && pn[k + 28] == 2 && pn[k + 42] == 2) {  //斜左
                    if (pn[k - 14] == 0 || pn[k + 56] == 0) { jqn[k + 14] = jqn[k + 14] + 1800; }
                }
                if (pn[k] == 2 && pn[k + 14] == 2 && pn[k + 28] == 0 && pn[k + 42] == 2) {  //斜左
                    if (pn[k - 14] == 0 || pn[k + 56] == 0) { jqn[k + 28] = jqn[k + 28] + 1800; }
                }
            } //j>4, i<12

            if (j < 12 && i < 12) {
                if (pn[k] == 2 && pn[k + 16] == 0 && pn[k + 32] == 2 && pn[k + 48] == 2) {  //右斜
                    if (pn[k - 16] == 0 || pn[k + 64] == 0) { jqn[k + 16] = jqn[k + 16] + 1800; }
                }
                if (pn[k] == 2 && pn[k + 16] == 2 && pn[k + 32] == 0 && pn[k + 48] == 2) {  //右斜
                    if (pn[k - 16] == 0 || pn[k + 64] == 0) { jqn[k + 32] = jqn[k + 32] + 1800; }
                }
            } //i<12&&j<12


            //嵌四 020220  022020  必杀点+3500  j<12  防越界
            if (j < 12) {
                if (pn[k - 1] == 0 && pn[k] == 2 && pn[k + 1] == 0 && pn[k + 2] == 2 && pn[k + 3] == 2 && pn[k + 4] == 0) {  //左右
                    jqn[k + 1] = jqn[k + 1] + 3500;
                }
                if (pn[k - 1] == 0 && pn[k] == 2 && pn[k + 1] == 2 && pn[k + 2] == 0 && pn[k + 3] == 2 && pn[k + 4] == 0) {  //左右
                    jqn[k + 2] = jqn[k + 2] + 3500;
                }
            }

            if (i < 12) {
                if (pn[k - 15] == 0 && pn[k] == 2 && pn[k + 15] == 0 && pn[k + 30] == 2 && pn[k + 45] == 2 && pn[k + 60] == 0) {  //上下
                    jqn[k + 15] = jqn[k + 15] + 3500;
                }
                if (pn[k - 15] == 0 && pn[k] == 2 && pn[k + 15] == 2 && pn[k + 30] == 0 && pn[k + 45] == 2 && pn[k + 60] == 0) {  //上下
                    jqn[k + 30] = jqn[k + 30] + 3500;
                }
            }

            if (j > 4 && i < 12) {
                if (pn[k - 14] == 0 && pn[k] == 2 && pn[k + 14] == 0 && pn[k + 28] == 2 && pn[k + 42] == 2 && pn[k + 56] == 0) {  //斜左
                    jqn[k + 14] = jqn[k + 14] + 3500;
                }
                if (pn[k - 14] == 0 && pn[k] == 2 && pn[k + 14] == 2 && pn[k + 28] == 0 && pn[k + 42] == 2 && pn[k + 56] == 0) {  //斜左
                    jqn[k + 28] = jqn[k + 28] + 3500;
                }
            }

            if (j < 12 && i < 12) {
                if (pn[k - 16] == 0 && pn[k] == 2 && pn[k + 16] == 0 && pn[k + 32] == 2 && pn[k + 48] == 2 && pn[k + 64] == 0) {  //右斜
                    jqn[k + 16] = jqn[k + 16] + 5500;
                }
                if (pn[k - 16] == 0 && pn[k] == 2 && pn[k + 16] == 2 && pn[k + 32] == 0 && pn[k + 48] == 2 && pn[k + 64] == 0) {  //右斜
                    jqn[k + 32] = jqn[k + 32] + 5500;
                }
            }

            //活四冲四 022220  122220  022221   
            //此是必杀点  +9000  j<12  防越界
            if (pn[k] == 2 && pn[k + 1] == 2 && pn[k + 2] == 2 && pn[k + 3] == 2) {  //左右
                if (j > 1 && pn[k - 1] == 0) { jqn[k - 1] = jqn[k - 1] + 9000 }
                if (j < 12 && pn[k + 4] == 0) { jqn[k + 4] = jqn[k + 4] + 9000 }
            }

            if (pn[k] == 2 && pn[k + 15] == 2 && pn[k + 30] == 2 && pn[k + 45] == 2) {  //上下
                if (i > 1 && pn[k - 15] == 0) { jqn[k - 15] = jqn[k - 15] + 9000 }
                if (i < 12 && pn[k + 60] == 0) { jqn[k + 60] = jqn[k + 60] + 9000 }
            }

            if (pn[k] == 2 && pn[k + 14] == 2 && pn[k + 28] == 2 && pn[k + 42] == 2) {//左对角
                if (i > 4 && j < 14 && pn[k - 14] == 0) { jqn[k - 14] = jqn[k - 14] + 9000 }
                if (i < 12 && j > 4 && pn[k + 56] == 0) { jqn[k + 56] = jqn[k + 56] + 9000 }
            }

            if (pn[k] == 2 && pn[k + 16] == 2 && pn[k + 32] == 2 && pn[k + 48] == 2) {//右对角     
                if (j > 1 && i < 12 && pn[k - 16] == 0) { jqn[k - 16] = jqn[k - 16] + 9000 }
                if (j < 12 && i < 12 && pn[k + 64] == 0) { jqn[k + 64] = jqn[k + 64] + 9000 }
            }
            //嵌五，此是必杀点 20222  22022  22202 +9000
            if (j < 12) {      // j<12  防越界
                if (pn[k] == 2 && pn[k + 1] == 0 && pn[k + 2] == 2 && pn[k + 3] == 2 && pn[k + 4] == 2) {  //左右 20222
                    jqn[k + 1] = jqn[k + 1] + 9000;
                }
                if (pn[k] == 2 && pn[k + 1] == 2 && pn[k + 2] == 0 && pn[k + 3] == 2 && pn[k + 4] == 2) {  //左右 22022
                    jqn[k + 2] = jqn[k + 2] + 9000;
                }
                if (pn[k] == 2 && pn[k + 1] == 2 && pn[k + 2] == 2 && pn[k + 3] == 0 && pn[k + 4] == 2) {  //左右 22202
                    jqn[k + 3] = jqn[k + 3] + 9000;
                }
            }  //j<12

            if (i < 12) {
                if (pn[k] == 2 && pn[k + 15] == 0 && pn[k + 30] == 2 && pn[k + 45] == 2 && pn[k + 60] == 2) {  //上下 20222
                    jqn[k + 15] = jqn[k + 15] + 9000;
                }
                if (pn[k] == 2 && pn[k + 15] == 2 && pn[k + 30] == 0 && pn[k + 45] == 2 && pn[k + 60] == 2) {  //上下 22022
                    jqn[k + 30] = jqn[k + 30] + 9000;
                }
                if (pn[k] == 2 && pn[k + 15] == 2 && pn[k + 30] == 2 && pn[k + 45] == 0 && pn[k + 60] == 2) {  //上下 22202
                    jqn[k + 45] = jqn[k + 45] + 9000;
                }
            }  //i<12

            if (j > 4 && i < 12) {
                if (pn[k] == 2 && pn[k + 14] == 0 && pn[k + 28] == 2 && pn[k + 42] == 2 && pn[k + 56] == 2) {  //斜左 20222
                    jqn[k + 14] = jqn[k + 14] + 9000;
                }
                if (pn[k] == 2 && pn[k + 14] == 2 && pn[k + 28] == 0 && pn[k + 42] == 2 && pn[k + 56] == 2) {  //斜左 22022
                    jqn[k + 28] = jqn[k + 28] + 9000;
                }
                if (pn[k] == 2 && pn[k + 14] == 2 && pn[k + 28] == 2 && pn[k + 42] == 0 && pn[k + 56] == 2) {  //斜左 22202
                    jqn[k + 42] = jqn[k + 42] + 9000;
                }
            }

            if (j < 12 && i < 12) {
                if (pn[k] == 2 && pn[k + 16] == 0 && pn[k + 32] == 2 && pn[k + 48] == 2 && pn[k + 64] == 2) {  //右斜 20222
                    jqn[k + 16] = jqn[k + 16] + 9000;
                }
                if (pn[k] == 2 && pn[k + 16] == 2 && pn[k + 32] == 0 && pn[k + 48] == 2 && pn[k + 64] == 2) {  //右斜 22022
                    jqn[k + 32] = jqn[k + 32] + 9000;
                }
                if (pn[k] == 2 && pn[k + 16] == 2 && pn[k + 32] == 2 && pn[k + 48] == 0 && pn[k + 64] == 2) {  //右斜 22202
                    jqn[k + 48] = jqn[k + 48] + 9000;
                }
            }

            //****************************
            //以下是黑棋估权计分
            //独子 左右上下 二对角 八方

            if (pn[k] == 1) {
                if (pn[k - 15] == 0) { jqn[k - 15] = jqn[k - 15] + 20 }
                if (pn[k + 15] == 0) { jqn[k + 15] = jqn[k + 15] + 20 }
                if (border_right) {
                    if (pn[k - 1] == 0) { jqn[k - 1] = jqn[k - 1] + 20 }
                    if (pn[k + 14] == 0) { jqn[k + 14] = jqn[k + 14] + 20 }
                    if (pn[k - 16] == 0) { jqn[k - 16] = jqn[k - 16] + 20 }

                } else if (border_left) {
                    if (pn[k + 1] == 0) { jqn[k + 1] = jqn[k + 1] + 20 }
                    if (pn[k + 16] == 0) { jqn[k + 16] = jqn[k + 16] + 20 }
                    if (pn[k - 14] == 0) { jqn[k - 14] = jqn[k - 14] + 20 }

                } else {
                    if (pn[k - 1] == 0) { jqn[k - 1] = jqn[k - 1] + 20 }
                    if (pn[k + 1] == 0) { jqn[k + 1] = jqn[k + 1] + 20 }
                    if (pn[k + 14] == 0) { jqn[k + 14] = jqn[k + 14] + 20 }
                    if (pn[k + 16] == 0) { jqn[k + 16] = jqn[k + 16] + 20 }
                    if (pn[k - 14] == 0) { jqn[k - 14] = jqn[k - 14] + 20 }
                    if (pn[k - 16] == 0) { jqn[k - 16] = jqn[k - 16] + 20 }
                }
            }

            //连二 11
            if (pn[k] == 1 && pn[k + 1] == 1) {  //左右
                if (border_left) {
                    if (pn[k + 2] == 0) { jqn[k + 2] = jqn[k + 2] + 300 }
                } else if ((k + 1) % 15 == 0) {
                    if (pn[k - 1] == 0) { jqn[k - 1] = jqn[k - 1] + 300 }
                } else if (border_right) {
                } else if ((k - 2) % 15 == 0) {
                    if (pn[k + 2] == 0) { jqn[k + 2] = jqn[k + 2] + 300 }
                } else if ((k + 2) % 15 == 0) {
                    if (pn[k - 1] == 0) { jqn[k - 1] = jqn[k - 1] + 300 }
                } else if (pn[k] == 1 && pn[k + 1] == 1) {
                    if (pn[k - 1] == 0) { jqn[k - 1] = jqn[k - 1] + 500 }
                    if (pn[k + 2] == 0) { jqn[k + 2] = jqn[k + 2] + 500 }
                }
            }

            if (pn[k] == 1 && pn[k + 15] == 1) {  //上下
                if ((k + 15) > 210 || (k + 30) > 210) {
                    // 下边框
                    if (pn[k - 15] == 0) { jqn[k - 15] = jqn[k - 15] + 300 }
                } else if ((k - 15) < 16 || k < 16) {
                    // 上边框
                    if (pn[k + 30] == 0) { jqn[k + 30] = jqn[k + 30] + 300 }
                } else {
                    if (pn[k - 15] == 0) { jqn[k - 15] = jqn[k - 15] + 500 }
                    if (pn[k + 30] == 0) { jqn[k + 30] = jqn[k + 30] + 500 }
                }
            }
            if (pn[k] == 1 && pn[k + 14] == 1) {  //左对角
                // 靠左边
                if ((k + 14 - 1) % 15 == 0 || (k - 2) % 15 == 0) {
                    if (k == 17) {
                        if (pn[k - 14] == 0) { jqn[k - 14] = jqn[k - 14] + 100 }
                    } else {
                        if (pn[k - 14] == 0) { jqn[k - 14] = jqn[k - 14] + 300 }
                    }
                } else if (border_right) {
                    if (k == 195) {
                        if (pn[k + 28] == 0) { jqn[k + 28] = jqn[k + 28] + 100 }
                    } else {
                        if (pn[k + 28] == 0) { jqn[k + 28] = jqn[k + 28] + 300 }
                    }
                } else if (border_left && (k + 14) % 15 == 0) {
                } else if ((k - 3) % 15 == 0) {
                    if (k < 28) {
                        if (pn[k - 14] == 0) { jqn[k - 14] = jqn[k - 14] + 100 }
                    } else {
                        if (pn[k - 14] == 0) { jqn[k - 14] = jqn[k - 14] + 500 }
                    }
                    if (pn[k + 28] == 0) { jqn[k + 28] = jqn[k + 28] + 100 }
                } else if ((k + 1) % 15 == 0) {
                    if (pn[k - 14] == 0) { jqn[k - 14] = jqn[k - 14] + 100 }
                    if (pn[k + 28] == 0) { jqn[k + 28] = jqn[k + 28] + 500 }
                } else if ((k + 1) % 15 == 0) {
                    if (pn[k - 14] == 0) { jqn[k - 14] = jqn[k - 14] + 100 }
                    if (pn[k + 28] == 0) { jqn[k + 28] = jqn[k + 28] + 300 }
                } else if (k == 18 || k == 194) {
                    if (pn[k - 14] == 0) { jqn[k - 14] = jqn[k - 14] + 100 }
                    if (pn[k + 28] == 0) { jqn[k + 28] = jqn[k + 28] + 100 }
                } else if (k == 18 || k == 194) {
                    if (pn[k - 14] == 0) { jqn[k - 14] = jqn[k - 14] + 100 }
                    if (pn[k + 28] == 0) { jqn[k + 28] = jqn[k + 28] + 100 }
                }
                else {
                    if (k < 28) {
                        if (pn[k - 14] == 0) { jqn[k - 14] = jqn[k - 14] + 100 }
                    } else {
                        if (pn[k - 14] == 0) { jqn[k - 14] = jqn[k - 14] + 500 }
                    }
                    if (k > 180) {
                        if (pn[k + 28] == 0) { jqn[k + 28] = jqn[k + 28] + 100 }
                    } else {
                        if (pn[k + 28] == 0) { jqn[k + 28] = jqn[k + 28] + 500 }
                    }
                }
            }
            if (pn[k] == 1 && pn[k + 16] == 1) {   //右对角                
                if ((k + 1) % 15 == 0) {
                    if (k == 29) {
                        if (pn[k - 16] == 0) { jqn[k - 16] = jqn[k - 16] + 100 }
                    } else {
                        if (pn[k - 16] == 0) { jqn[k - 16] = jqn[k - 16] + 300 }
                    }
                } else if (border_left) {
                    if (k == 181) {
                        if (pn[k + 32] == 0) { jqn[k + 32] = jqn[k + 32] + 100 }
                    } else {
                        if (pn[k + 32] == 0) { jqn[k + 32] = jqn[k + 32] + 300 }
                    }
                } else if ((k - 2) % 15 == 0) {
                    if (k > 180) {
                        if (pn[k + 32] == 0) { jqn[k + 32] = jqn[k + 32] + 100 }
                        if (pn[k + 32] == 0) { jqn[k + 32] = jqn[k + 32] + 100 }
                    } else {
                        if (pn[k - 16] == 0) { jqn[k - 16] = jqn[k - 1] + 100 }
                        if (pn[k + 32] == 0) { jqn[k + 32] = jqn[k + 32] + 300 }
                    }
                } else if (k < 31) {
                    if (pn[k - 16] == 0) { jqn[k - 16] = jqn[k - 1] + 100 }
                    if (pn[k + 32] == 0) { jqn[k + 32] = jqn[k + 32] + 300 }
                } else if (k > 180) {
                    if (pn[k + 32] == 0) { jqn[k + 32] = jqn[k + 32] + 100 }
                    if (pn[k - 16] == 0) { jqn[k - 16] = jqn[k - 16] + 500 }
                }
                else {
                    if (pn[k - 16] == 0) { jqn[k - 16] = jqn[k - 16] + 500 }
                    if (pn[k + 32] == 0) { jqn[k + 32] = jqn[k + 32] + 500 }
                }
            }
            // //嵌三   01010 
            if (pn[k] == 1 && pn[k + 1] == 0 && pn[k + 2] == 1) {  //左右
                if (border_left || (k + 2) % 15 == 0) {
                    if (k == 1 || k == 13 || k == 211 || k == 223) {
                        jqn[k + 1] = jqn[k + 1] + 100
                    } else {
                        jqn[k + 1] = jqn[k + 1] + 300
                    }
                } else if (k < 16 || k > 210) {
                    jqn[k + 1] = jqn[k + 1] + 100
                } else if ((k + 1) % 15 == 0) {
                }
                else {
                    jqn[k + 1] = jqn[k + 1] + 500
                }
            }
            if (pn[k] == 1 && pn[k + 15] == 0 && pn[k + 30] == 1) {  //上下
                if (k > 180) {
                    if (k == 181 || k == 195) {
                        jqn[k + 15] = jqn[k + 15] + 100
                    } else {
                        jqn[k + 15] = jqn[k + 15] + 300
                    }
                } else if (k < 16) {
                    if (k == 1 || k == 15) {
                        jqn[k + 15] = jqn[k + 15] + 100
                    } else {
                        jqn[k + 15] = jqn[k + 15] + 300
                    }
                } else if (border_left || border_right) {
                    jqn[k + 15] = jqn[k + 15] + 100
                }
                else {
                    jqn[k + 15] = jqn[k + 15] + 500
                }
            }
            if (pn[k] == 1 && pn[k + 14] == 0 && pn[k + 28] == 1) {//左对角
                if (k == 3 || k == 195) {
                } else if (k == 15 || k == 183) {
                    jqn[k + 14] = jqn[k + 14] + 300
                }
                else {
                    jqn[k + 14] = jqn[k + 14] + 500
                }
            }
            if (pn[k] == 1 && pn[k + 16] == 0 && pn[k + 32] == 1) {//右对角
                if (k == 13 || k == 181) {
                } else if (k == 1 || k == 193) {
                    jqn[k + 16] = jqn[k + 16] + 300
                }
                else {
                    jqn[k + 16] = jqn[k + 16] + 500
                }
            }

            //三连，眠三21110  01112 逢三必进
            if (pn[k] == 1 && pn[k + 1] == 1 && pn[k + 2] == 1) {  //左右
                if ((k + 1) % 15 == 0) {
                } else if (border_right) {
                } else if ((k + 2) % 15 == 0) {
                    if (pn[k - 1] == 0) { jqn[k - 1] = jqn[k - 1] + 1000 }
                } else if (border_left) {
                    if (pn[k + 3] == 0) { jqn[k + 3] = jqn[k + 3] + 1000 }
                } else {
                    if (pn[k - 1] == 0) { jqn[k - 1] = jqn[k - 1] + 3000 }
                    if (pn[k + 3] == 0) { jqn[k + 3] = jqn[k + 3] + 3000 }
                }
            }
            if (pn[k] == 1 && pn[k + 15] == 1 && pn[k + 30] == 1) {  //上下  
                if (k < 31) {
                    if (pn[k - 15] == 0) { jqn[k - 15] = jqn[k - 15] + 1000 }
                    if (pn[k + 45] == 0) { jqn[k + 45] = jqn[k + 45] + 3000 }
                } else if (k > 165) {
                    if (pn[k - 15] == 0) { jqn[k - 15] = jqn[k - 15] + 3000 }
                    if (pn[k + 45] == 0) { jqn[k + 45] = jqn[k + 45] + 1000 }
                } else {
                    if (pn[k - 15] == 0) { jqn[k - 15] = jqn[k - 15] + 3000 }
                    if (pn[k + 45] == 0) { jqn[k + 45] = jqn[k + 45] + 3000 }
                }
            }

            if (pn[k] == 1 && pn[k - 14] == 1 && pn[k - 28] == 1) {//左对角
                if (pn[k + 14] == 0) { jqn[k + 14] = jqn[k + 14] + 3000 }
                if (pn[k - 42] == 0) { jqn[k - 42] = jqn[k - 42] + 3000 }
                if (pn[k + 2] == 0) { jqn[k + 2] = jqn[k + 2] + 3050 }
                if (pn[k - 30] == 0) { jqn[k - 30] = jqn[k - 30] + 3050 } //破梅花阵
            }

            if (pn[k] == 1 && pn[k + 16] == 1 && pn[k + 32] == 1) {//右对角
                if (pn[k - 16] == 0) { jqn[k - 16] = jqn[k - 16] + 3000 }
                if (pn[k + 48] == 0) { jqn[k + 48] = jqn[k + 48] + 3000 }
                if (pn[k + 2] == 0) { jqn[k + 2] = jqn[k + 2] + 3050 }
                if (pn[k + 30] == 0) { jqn[k + 30] = jqn[k + 30] + 3050 }
            }    //破梅花阵

            //三连，活三  01110  逢三必堵
            if (pn[k - 1] == 0 && pn[k] == 1 && pn[k + 1] == 1 && pn[k + 2] == 1 && pn[k + 3] == 0) {  //左右
                if (pn[k - 1] == 0) { jqn[k - 1] = jqn[k - 1] + 3300 }
                if (pn[k + 3] == 0) { jqn[k + 3] = jqn[k + 3] + 3300 }
            }

            if (pn[k - 15] == 0 && pn[k] == 1 && pn[k + 15] == 1 && pn[k + 30] == 1 && pn[k + 45] == 0) {  //上下
                if (pn[k - 15] == 0) { jqn[k - 15] = jqn[k - 15] + 3300 }
                if (pn[k + 45] == 0) { jqn[k + 45] = jqn[k + 45] + 3300 }
            }

            if (pn[k - 14] == 0 && pn[k] == 1 && pn[k + 14] == 1 && pn[k + 28] == 1 && pn[k + 42] == 0) {//左对角
                if (pn[k - 14] == 0) { jqn[k - 14] = jqn[k - 14] + 3300 }
                if (pn[k + 42] == 0) { jqn[k + 42] = jqn[k + 42] + 3300 }
            }

            if (pn[k - 16] == 0 && pn[k] == 1 && pn[k + 16] == 1 && pn[k + 32] == 1 && pn[k + 48] == 0) {//右对角
                if (pn[k - 16] == 0) { jqn[k - 16] = jqn[k - 16] + 3300 }
                if (pn[k + 48] == 0) { jqn[k + 48] = jqn[k + 48] + 3300 }
            }

            //嵌四 010110   011010   必杀点 +3500
            if (pn[k - 1] == 0 && pn[k] == 1 && pn[k + 1] == 0 && pn[k + 2] == 1 && pn[k + 3] == 1 && pn[k + 4] == 0) {  //左右
                jqn[k + 1] = jqn[k + 1] + 3500;
            }
            if (pn[k - 1] == 0 && pn[k] == 1 && pn[k + 1] == 1 && pn[k + 2] == 0 && pn[k + 3] == 1 && pn[k + 4] == 0) {  //左右
                jqn[k + 2] = jqn[k + 2] + 3500;
            }

            if (pn[k - 15] == 0 && pn[k] == 1 && pn[k + 15] == 0 && pn[k + 30] == 1 && pn[k + 45] == 1 && pn[k + 60] == 0) {  //上下
                jqn[k + 15] = jqn[k + 15] + 3500;
            }
            if (pn[k - 15] == 0 && pn[k] == 1 && pn[k + 15] == 1 && pn[k + 30] == 0 && pn[k + 45] == 1 && pn[k + 60] == 0) {  //上下
                jqn[k + 30] = jqn[k + 30] + 3500;
            }

            if (pn[k - 14] == 0 && pn[k] == 1 && pn[k + 14] == 0 && pn[k + 28] == 1 && pn[k + 42] == 1 && pn[k + 56] == 0) {  //斜左
                jqn[k + 14] = jqn[k + 14] + 3500;
            }
            if (pn[k - 14] == 0 && pn[k] == 1 && pn[k + 14] == 1 && pn[k + 28] == 0 && pn[k + 42] == 1 && pn[k + 56] == 0) {  //斜左
                jqn[k + 28] = jqn[k + 28] + 3500;
            }

            if (pn[k - 16] == 0 && pn[k] == 1 && pn[k + 16] == 0 && pn[k + 32] == 1 && pn[k + 48] == 1 && pn[k + 64] == 0) {  //右斜
                jqn[k + 16] = jqn[k + 16] + 3500;
            }
            if (pn[k - 16] == 0 && pn[k] == 1 && pn[k + 16] == 1 && pn[k + 32] == 0 && pn[k + 48] == 1 && pn[k + 64] == 0) {  //右斜
                jqn[k + 32] = jqn[k + 32] + 3500;
            }

            //活四冲四 此是必杀点 211110  011112   +6000
            //黑有此白必堵，此是必杀点 如白无连五则必应 
            if (pn[k] == 1 && pn[k + 1] == 1 && pn[k + 2] == 1 && pn[k + 3] == 1) {  //左右
                if (pn[k - 1] == 0) { jqn[k - 1] = jqn[k - 1] + 7000 }
                if (pn[k + 4] == 0) { jqn[k + 4] = jqn[k + 4] + 7000 }
            }

            if (pn[k] == 1 && pn[k + 15] == 1 && pn[k + 30] == 1 && pn[k + 45] == 1) {  //上下
                if (pn[k - 15] == 0) { jqn[k - 15] = jqn[k - 15] + 7000 }
                if (pn[k + 60] == 0) { jqn[k + 60] = jqn[k + 60] + 7000 }
            }
            if (pn[k] == 1 && pn[k - 14] == 1 && pn[k - 28] == 1 && pn[k - 42] == 1) {//左对角
                if (pn[k + 14] == 0) { jqn[k + 14] = jqn[k + 14] + 7000 }
                if (pn[k - 56] == 0) { jqn[k - 56] = jqn[k - 56] + 7000 }
            }

            if (pn[k] == 1 && pn[k + 16] == 1 && pn[k + 32] == 1 && pn[k + 48] == 1) {//右对角
                if (pn[k - 16] == 0) { jqn[k - 16] = jqn[k - 16] + 7000 }
                if (pn[k + 64] == 0) { jqn[k + 64] = jqn[k + 64] + 7000 }
            }


            //嵌五 10111  11011  11101   +6000
            //此是必杀点 如白无连五则必应 
            if (pn[k] == 1 && pn[k + 1] == 0 && pn[k + 2] == 1 && pn[k + 3] == 1 && pn[k + 4] == 1) {  //左右 10111
                jqn[k + 1] = jqn[k + 1] + 7000;
            }
            if (pn[k] == 1 && pn[k + 1] == 1 && pn[k + 2] == 0 && pn[k + 3] == 1 && pn[k + 4] == 1) {  //左右 11011
                jqn[k + 2] = jqn[k + 2] + 7000;
            }
            if (pn[k] == 1 && pn[k + 1] == 1 && pn[k + 2] == 1 && pn[k + 3] == 0 && pn[k + 4] == 1) {  //左右 11101
                jqn[k + 3] = jqn[k + 3] + 7000;
            }

            if (pn[k] == 1 && pn[k + 15] == 0 && pn[k + 30] == 1 && pn[k + 45] == 1 && pn[k + 60] == 1) {  //上下 10111
                jqn[k + 15] = jqn[k + 15] + 7000;
            }
            if (pn[k] == 1 && pn[k + 15] == 1 && pn[k + 30] == 0 && pn[k + 45] == 1 && pn[k + 60] == 1) {  //上下 11011
                jqn[k + 30] = jqn[k + 30] + 7000;
            }
            if (pn[k] == 1 && pn[k + 15] == 1 && pn[k + 30] == 1 && pn[k + 45] == 0 && pn[k + 60] == 1) {  //上下 11101
                jqn[k + 45] = jqn[k + 45] + 7000;
            }

            if (pn[k] == 1 && pn[k + 14] == 0 && pn[k + 28] == 1 && pn[k + 42] == 1 && pn[k + 56] == 1) {  //斜左 10111
                jqn[k + 14] = jqn[k + 14] + 7000;
            }
            if (pn[k] == 1 && pn[k + 14] == 1 && pn[k + 28] == 0 && pn[k + 42] == 1 && pn[k + 56] == 1) {  //斜左 11011
                jqn[k + 28] = jqn[k + 28] + 7000;
            }
            if (pn[k] == 1 && pn[k + 14] == 1 && pn[k + 28] == 1 && pn[k + 42] == 0 && pn[k + 56] == 1) {  //斜左 11101
                jqn[k + 42] = jqn[k + 42] + 7000;
            }

            if (pn[k] == 1 && pn[k + 16] == 0 && pn[k + 32] == 1 && pn[k + 48] == 1 && pn[k + 64] == 1) {  //右斜 10111
                jqn[k + 16] = jqn[k + 16] + 7000;
            }
            if (pn[k] == 1 && pn[k + 16] == 1 && pn[k + 32] == 0 && pn[k + 48] == 1 && pn[k + 64] == 1) {  //右斜 11011
                jqn[k + 32] = jqn[k + 32] + 7000;
            }
            if (pn[k] == 1 && pn[k + 16] == 1 && pn[k + 32] == 1 && pn[k + 48] == 0 && pn[k + 64] == 1) {  //右斜 11101
                jqn[k + 48] = jqn[k + 48] + 7000;
            }
        }
    }



    // 把落子位置权数组重新赋值给 全局变量 以便调用
    ChessStatus.AllchessQ = jqn
    // console.log("权重", jqn)
    // 绘权重图形
    // draw_jqn()
    function draw_jqn() {
        for (let i = 1; i <= jqn.length - 1; i++) {
            const arr = jqn[i];
            if (jqn[i] != "0") {
                e = document.querySelector('div[number=\"' + (i) + '\"]')
                // e.style.backgroundColor = "red"
                e.style.lineHeight = "38px"
                e.style.color = "#000"
                e.style.textAlign = "center"
                e.innerHTML = arr
                // console.log('qz', arr, e.innerHTML)
            }

        }
    }
}

function AI_q(obj) {
    xy = obj.id.split(',')
    y = xy[0]
    x = xy[1]

    let size = 14
    let jqn = new Array(225) //所有权重
    let pn = ChessStatus.Allchess //所有落子信息 0未落子 1黑方 2白方

    // for (i = 1; i <= 225; i++) {
    //     jqn[i] = 0;
    // }
    for (let i = 0; i < 15; i++) {    //遍历scan B & W 子
        let k
        for (j = 0; j < 15; j++) {
            k = (i - 1) * 15 + j;    //pn(n) number            
            ChessStatus.colorPad[i, j] = 0
        }
    }

    // 几个临时数组变量用来倒腾数组推入元素

    var winarr = [], temparr = [], temparr_list = []
    /**
     *私有函数，某个方向五连字的可能性的组合
     *
     * @param {*} temparr
     */
    function zhuhe_keneng(temparr) {
        for (let i = 0; i < 5 && i <= temparr.length - 5; i++) {
            for (let j = 0; j < 5; j++) {
                temparr_list.push(temparr[i + j])
            }
            if (temparr_list.length == 5) {
                winarr.push(temparr_list)
                temparr_list = []
            }
        }
    }
    // 左
    for (let i = 4; i >= 1; i--) {
        if (Number(y) - i >= 0) {
            temparr.push(x + "," + String(Number(y) - i))
        }
    }
    temparr.push(x + "," + y)
    // 右
    for (let i = 1; i < 5; i++) {
        if (Number(y) + i <= 16) {
            temparr.push(x + "," + String(Number(y) + i))
        }

    }
    zhuhe_keneng(temparr)


    // 上
    temparr = []
    for (let i = 4; i >= 1; i--) {
        if (Number(x) - i >= 0) {
            temparr.push(String(Number(x) - i + "," + y))
        }
    }
    temparr.push(x + "," + y)
    //下
    for (let i = 1; i < 5; i++) {
        if (Number(x) + i <= 16) {
            temparr.push(String(Number(x) + i + "," + y))
        }

    }
    zhuhe_keneng(temparr)

    // 左上
    temparr = []
    for (let i = 4; i >= 1; i--) {
        if (Number(y) - i >= 0 && Number(x) - i >= 0) {
            temparr.push(String(Number(x) - i) + "," + String(Number(y) - i))
        }

    }
    temparr.push(x + "," + y)
    // 右下
    for (let i = 1; i < 5; i++) {
        if (Number(y) + i <= 16 && Number(x) + i <= 16) {
            temparr.push(String(Number(x) + i) + "," + String(Number(y) + i))
        }

    }
    zhuhe_keneng(temparr)

    //  左下
    temparr = []
    for (let i = 4; i >= 1; i--) {
        if (Number(x) + i <= 16 && Number(y) - i >= 0) {
            temparr.push(String(Number(x) + i) + "," + String(Number(y) - i))
        }

    }
    temparr.push(x + "," + y)
    // // 右上
    for (let i = 1; i < 5; i++) {
        if (Number(x) - i >= 0 && Number(y) + i <= 16) {
            temparr.push(String(Number(x) - i) + "," + String(Number(y) + i))
        }

    }
    zhuhe_keneng(temparr)
    ChessStatus.win_Zi_arr = winarr
    return winarr;

}

/**
 *封装用xpath 获取文档元素
 * @param {string} xpath
 * @return {Element} 获取到的元素 
 */
function getElementByXpath(xpath) {
    var element = document.evaluate(xpath, document).iterateNext();
    return element;
}



// 更新计时器显示的时间
function updateTimerDisplay(timeInSeconds, element) {
    element.innerHTML = formatTime(timeInSeconds)
}

// 格式化时间为小时、分钟和秒的形式
function formatTime(timeInSeconds) {
    // const hours = Math.floor(timeInSeconds / 3600);
    const minutes = Math.floor((timeInSeconds % 3600) / 60);
    const seconds = timeInSeconds % 60;
    return `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
}
// 启动计时器
function startTimer(element, seconds) {
    timerInterval = setInterval(function () {
        seconds++;
        updateTimerDisplay(seconds, element)
    }, 1000)
    // return seconds
}
// 暂停计时器
function stopTimer(timerInterval) {
    clearInterval(timerInterval)
}
